/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package TimeRecording.business;

/**
 *
 * @author david
 */
public class IntegerTimeRange implements Cloneable{

    private int minutesFrom;
    private int minutesTo;

    public IntegerTimeRange(int minutesFrom, int minutesTo) {
        this.minutesFrom = minutesFrom;
        this.minutesTo = minutesTo;
    }

    public int getMinutesFrom() {
        return minutesFrom;
    }

    public int getMinutesTo() {
        return minutesTo;
    }

    public int getMinutes() {
        return minutesTo - minutesFrom;
    }

    public void crop(IntegerTimeRange crop) {
        if (this.minutesFrom < crop.minutesFrom) {
            this.minutesFrom = crop.minutesFrom;
        }
        if (this.minutesTo > crop.minutesTo) {
            this.minutesTo = crop.minutesTo;
        }
    }

    public void normalise(int offset) {
        this.minutesFrom -= offset;
        this.minutesTo -= offset;
    }

    public boolean isEmpty() {
        return minutesTo <= minutesFrom;
    }

    @Override
    public IntegerTimeRange clone() {
        try {
            return (IntegerTimeRange)super.clone();
        } catch (CloneNotSupportedException ex) {
            return null;
        }
    }
}
